package cn.dengta.webapp.trade.dao;

import cn.dengta.webapp.base.dao.BaseDao;
import cn.dengta.webapp.trade.entity.MaleRecommendStatistics;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

/**
 * 男用户推荐分值统计 Mapper 接口
 *
 * @author zw
 * @since 2022-10-09
 */
public interface MaleRecommendStatisticsDao extends BaseDao<MaleRecommendStatistics> {

	/** 更新某个字段值 */
	@Update("UPDATE dt_male_recommend_statistics SET ${field} = #{score} WHERE id = #{userId}")
	int coverFieldValue(@Param("field") String field, @Param("score") Integer score, @Param("userId") Long userId);

	@Update("UPDATE dt_male_recommend_statistics SET ${field} = ${field} + #{score} WHERE id = #{userId}")
	int addFieldValue(@Param("field") String field, @Param("score") Integer score, @Param("userId") Long userId);

	@Update("UPDATE dt_male_recommend_statistics SET ${field} = 0")
	void resetFieldScore(@Param("field") String field);

	@Update("UPDATE dt_user u SET u.sort=(SELECT SUM(login+reply_rate+dig+donate) FROM dt_male_recommend_statistics WHERE id = u.id) WHERE gender = 1")
	void updateTotalSort();

}
